Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

fscache: load directories only once #205

Merged
merged 1 commit into from
Jun 25, 2014

Conversation

kblees
Copy link

@kblees kblees commented Jun 24, 2014

If multiple threads access a directory that is not yet in the cache, the
directory will be loaded by each thread. Only one of the results is added
to the cache, all others are leaked. This wastes performance and memory.

On cache miss, add a future object to the cache to indicate that the
directory is currently being loaded. Subsequent threads register themselves
with the future object and wait. When the first thread has loaded the
directory, it replaces the future object with the result and notifies
waiting threads.

Signed-off-by: Karsten Blees blees@dcon.de

If multiple threads access a directory that is not yet in the cache, the
directory will be loaded by each thread. Only one of the results is added
to the cache, all others are leaked. This wastes performance and memory.

On cache miss, add a future object to the cache to indicate that the
directory is currently being loaded. Subsequent threads register themselves
with the future object and wait. When the first thread has loaded the
directory, it replaces the future object with the result and notifies
waiting threads.

Signed-off-by: Karsten Blees <blees@dcon.de>
* Looks up or creates a cache entry for the specified key.
*/
static struct fsentry *fscache_get(struct fsentry *key)
{
struct fsentry *fse;
struct fsentry *fse, *future, *waiter;

EnterCriticalSection(&mutex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. From http://msdn.microsoft.com/en-us/library/windows/desktop/ms682608%28v=vs.85%29.aspx I expected that the second thread to hit the same code path would have to wait until the first one added the entry, and therefore would not add another entry... (sorry if I am stupidly missing anything)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual loading is done outside the critical section (see lines 290/325 below). We don't want to block concurrent readers while doing expensive IO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad for missing this! Thanks for the education!

@buildhive
Copy link

MSysGit - the development behind Git for Windows » git #236 SUCCESS
This pull request looks good
(what's this?)

dscho added a commit that referenced this pull request Jun 25, 2014
@dscho dscho merged commit b128d9c into msysgit:maint-1.9 Jun 25, 2014
@dscho
Copy link
Member

dscho commented Jun 25, 2014

Thank you so much! With contributors like you, it is really fun to maintain Git for Windows...

dscho added a commit that referenced this pull request Dec 19, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants